package com.yty.newconsult.common;

import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
@Component
public class SessionManager {
    private static ConcurrentHashMap<String, Channel> sessionMap = new ConcurrentHashMap<String, Channel>();
    public static void addSession(String id, Channel channel) {
        sessionMap.put(id, channel);
    }
    public static void removeById(String id) {
        sessionMap.remove(id);
    }
    public static void removeByChannel(Channel channel) {
        sessionMap.forEach((k,v)->{
            if(v.equals(channel)) {
                sessionMap.remove(k);
            }
        });
    }
    public static Channel getSession(String id) {
        return sessionMap.get(id);
    }
}

